<template>
	<view>
		<view class="top-container">
			<view  style="background-color: #f63832;padding: 20rpx">
				<u-search  v-model="keyword" @custom="search" @search="search" placeholder="搜索关键词"  :show-action="false" action-text="搜索" bg-color="#FBFBFB" border-color="#F5F5F5"  :animation="false" shape="round" search-icon="search" ></u-search>
			</view>
		    <view class="total p-0-30 d-s-c f24 gray9">
                <span class="pr20">
                    朋友总人数：
                    <text class="red">{{statistics.total}}</text>
                    人
                </span>
                <span class="pr20">
                    {{setting.agent_user_name}}总人数：
                    <text class="red">{{statistics.agent_user_num}}</text>
                    人
                </span>
                <span class="pr20">
                    非{{setting.agent_user_name}}总人数：
                    <text class="red">{{statistics.user_num}}</text>
                    人
                </span>
			</view>
		</view>

		<!--列表-->
		<scroll-view scroll-y="true" class="scroll-Y" :style="'height:' + scrollviewHigh + 'px;'" lower-threshold="50"
		 @scrolltolower="scrolltolowerFunc">
			<view class="p-0-30 ">
                <view class="hlbblock30" style="width: 96%;position: relative;overflow: hidden" v-for="(item,index) in tableData" :key="index">
                    <view style="padding: 0 30rpx;background-color: #F5F5F5;border-radius: 20rpx;height: 40rpx;position: absolute;top: 40rpx;left: 525rpx; white-space: nowrap;font-size: 20rpx;color: rgba(0,0,0,0.47)">
                        {{item.create_time}}
                    </view>
                    <view style="display: flex;align-items: center">
                        <view>
                            <image :src="item.user.avatarUrl" style="width: 90rpx;height: 90rpx;border-radius: 45rpx" mode="aspectFill"></image>
                        </view>
                        <view style="margin-left: 15rpx">
                            <view style="font-weight: bold">
                                {{ item.user.nickName }}
                            </view>
                            <view style="display: flex">
                                <view style="padding:5rpx 15rpx ;background-color: #EBF4FF;border: 1px rgba(105,171,255,0.28) solid;border-radius: 8rpx;display: flex;align-items: center;color: #69ABFF;font-size: 18rpx">
                                    <image src="/static/images/commission/mobile.png" style="width: 25rpx" mode="widthFix"></image>
                                    <view style="line-height: 25rpx">
                                        {{item.user.mobile}}
                                    </view>
                                </view>
                            </view>
                        </view>
                    </view>
					
                    <view class="fsc" style="padding-top: 30rpx">
                        <view style="text-align: center;width: 50%;border-right: 1px solid #DEDEDE">
                            <view style="color: rgba(0,0,0,0.56);font-size: 20rpx">
                                销售额
                            </view>
                            <view style="color:#FE6A33;font-size: 32rpx">
                                ￥{{ item.user.expend_money }}
                            </view>
                        </view>
                        <view style="text-align: center;width: 50%">
                            <view style="color: rgba(0,0,0,0.56);font-size: 20rpx">
                                等级
                            </view>
                            <view style="color:rgba(0,0,0,0.56);font-size: 32rpx;display: flex;align-items: center;justify-content: center;">
								<image :src="'/static/images/commission/lv' + item.agent.grade_id + '.png'" style="width: 80rpx;display: inline-block" mode="widthFix"></image>
								<view style="">
									{{ item.agent ? item.agent.grade.name : '会员' }}
								</view>
                            </view>
                        </view>
                    </view>
                </view>
				
				<!--<view class="border-b p-20-0" v-for="(item,index) in tableData" :key="index">
					<view class="d-b-c">
						<view class="agent-team-photo">
							<image :src="item.user.avatarUrl" mode="aspectFill"></image>
						</view>
						<view class="flex-1 ml20 f24">
							<view class="d-b-c">
								<text class="f28 gray3">{{ item.user.nickName }}</text>
								<text class="gray9">{{ item.create_time }}</text>
							</view>
							<view class="d-b-c">
								<text class="gray9">￥{{ item.user.expend_money }}</text>
								<text class="gray9" v-if="item.agent"> {{ item.agent.first_num + item.agent.second_num + item.agent.third_num }}个成员</text>
							</view>
						</view>
					</view>
				</view>-->
				
				<!-- 没有记录 -->
				<view class="d-c-c p30" v-if="tableData.length==0 && !loading">
					<text class="iconfont icon-wushuju"></text>
					<text class="cont">亲，暂无相关记录哦</text>
				</view>
				<uni-load-more v-else :loadingType="loadingType"></uni-load-more>
			</view>
		</scroll-view>
	</view>
</template>

<script>
    var _self;
	import uniLoadMore from "@/components/uni-load-more.vue";
	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				/*手机高度*/
				phoneHeight: 0,
				/*可滚动视图区域高度*/
				scrollviewHigh: 0,
				/*状态选中*/
				state_active: 0,
				/*数据列表*/
				tableData: [],
				setting: [],
                statistics: [],
				teamTotal: 0,
				page: 1,
				no_more: false,
				tabList: [],
				list_rows: 15,
				loading: true,
                salesort:'up',
                keyword:''
			}
		},
		computed: {
			/*加载中状态*/
			loadingType() {
				if (this.loading) {
					return 1;
				} else {
					if (this.tableData.length != 0 && this.no_more) {
						return 2;
					} else {
						return 0;
					}
				}
			}
		},
		mounted() {
		    _self = this;
			/*初始化*/
			this.init();
			/*获取数据*/
			this.getData();
		},
		methods: {
			
			/*初始化*/
			init() {
				let self = this;
				uni.getSystemInfo({
					success(res) {
						self.phoneHeight = res.windowHeight;
						// 计算组件的高度
						let view = uni.createSelectorQuery().select('.top-container');
						view.boundingClientRect(data => {
							let h = self.phoneHeight - data.height;
							self.scrollviewHigh = h;
						}).exec();
					}
				});
			},
            salefun(){
                let self = this;
                self.salesort=='up'?self.salesort='down':self.salesort='up' ;
                self.page =1;
                self.tableData = [];
                self.getData();
            },
            search(){
                let self = this;

                self.page =1;
                self.tableData = [];
                self.getData();
            },
			
			/*获取数据*/
			getData() {
				let self = this;
				self.loading = true;
				self._get('plus.agent.team/lists', {
					level: self.state_active + 1,
					page: self.page || 1,
					list_rows: self.list_rows,
                    salesort:self.salesort=='up'?0:1,
                    keyword :self.keyword
				}, function(res) {
				    console.log(res)
					self.loading = false;
					self.teamTotal = res.data.agent.first_num;
					let data = res.data;
					// 导航栏数据
					self.tabList = [{
						value: 1,
						text: data.words.team.words.first.value,
						total: data.agent.first_num
					}];
					if (data.setting.level >= 2) {
						self.tabList.push({
							value: 2,
							text: data.words.team.words.second.value,
							total: data.agent.second_num
						});
						self.teamTotal += data.agent.second_num;
					}
					if (data.setting.level == 3) {
						self.tabList.push({
							value: 3,
							text: data.words.team.words.third.value,
							total: data.agent.third_num
						});
						self.teamTotal += data.agent.third_num;
					}
					self.tableData = self.tableData.concat(data.list.data);
					self.last_page = data.list.last_page;
					self.setting = data.setting;
					self.statistics = data.statistics;
					if (self.last_page <= 1) {
						self.no_more = true;
					}
				},null,function(){
					self.loading = false;
				});
			},

			/*切换类别*/
			stateFunc(e) {
				let self = this;
				if(e!=self.state_active){
					self.tableData = [];
					self.page = 1;
					self.state_active = e;
					self.getData();
				}
			},

			/*可滚动视图区域到底触发*/
			scrolltolowerFunc() {
				let self = this;
				if (self.no_more) {
					return;
				}
				self.page++;
				if (self.page <= self.last_page) {
					self.getData();
				} else {
					self.no_more = true;
				}
			}
		}
	}
</script>

<style>
    page{
        background-color: #F5F5F5;
    }

    .tab-item2 {
        height: 96rpx;
        font-size: 32rpx;
        color: rgba(255, 255, 255, 0.50);
       width: 25%;
        text-align: center;

    }

    .tab-item2.active2 {
        margin-bottom: -2px;
        color: #FFFFFF;
        font-size: 32rpx;
        font-weight: bold;
        position: relative;
        width: 25%;
    }

    .tab-item2.active2::after {
        content: '';
        width: 72rpx;
        height: 8rpx;
        background: #FFFFFF;
        border-radius: 4rpx;
        position: absolute;
        bottom: 16rpx;
        left:25%;

    }






	.top-container .total {
		height: 80rpx;
	}

	.agent-team-photo,
	.agent-team-photo image {
		width: 80rpx;
		height: 80rpx;
		border-radius: 50%;
	}
</style>
